Skip to content

Add Crr Cascade capabilities to backbeat crr replication#2747

Open
SylvainSenechal wants to merge 1 commit into
development/9.5from
improvement/BB-767
Open

Add Crr Cascade capabilities to backbeat crr replication#2747
SylvainSenechal wants to merge 1 commit into
development/9.5from
improvement/BB-767

Conversation

@SylvainSenechal

@SylvainSenechal SylvainSenechal commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Issue: BB-767

Related PRs :
Arsenal : scality/Arsenal#2628
Cloudserver : scality/cloudserver#6179
CloudserverClient : scality/cloudserverclient#24
S3utils : scality/s3utils#395

@bert-e

bert-e commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Hello sylvainsenechal,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request TBA
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

Comment thread package.json Outdated
Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
@claude

claude Bot commented Jun 3, 2026

Copy link
Copy Markdown
  • package.json:54 — @scality/cloudserverclient uses a local file path (file:../cloudserverclient/...). Must be changed to a proper registry or git-pinned reference before merge.
    - ReplicateObject.js:6 — checkCrrCascadeEvent and getMicroVersionId() do not appear to exist in arsenal 8.3.9. Arsenal version bump likely needed.
    - ReplicateObject.js:743 — Any 409 from destination putMetadata is assumed to be cascade-stale and marked COMPLETED. Consider using a more specific signal to avoid silently skipping replication if 409 is returned for other reasons.

    Review by Claude Code

@SylvainSenechal SylvainSenechal marked this pull request as ready for review June 3, 2026 16:15
Comment thread extensions/replication/tasks/ReplicateObject.js

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can functional tests instead of just these,
But waiting for Arsenal/cloudserver to be merged, as it will be easier to make these tests (functional tests in backbeat rely on an image of cloudserver)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping unit test is good, functional test should just be an addition?

Comment thread package.json Outdated
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.58491% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.36%. Comparing base (295fa38) to head (8580536).

Files with missing lines Patch % Lines
extensions/replication/tasks/ReplicateObject.js 73.58% 14 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
extensions/replication/tasks/ReplicateObject.js 89.53% <73.58%> (-2.75%) ⬇️

... and 1 file with indirect coverage changes

Components Coverage Δ
Bucket Notification 80.22% <ø> (ø)
Core Library 81.58% <ø> (-0.06%) ⬇️
Ingestion 70.13% <ø> (ø)
Lifecycle 79.71% <ø> (ø)
Oplog Populator 85.83% <ø> (ø)
Replication 61.54% <73.58%> (-0.03%) ⬇️
Bucket Scanner 85.76% <ø> (ø)
@@                 Coverage Diff                 @@
##           development/9.5    #2747      +/-   ##
===================================================
- Coverage            75.42%   75.36%   -0.07%     
===================================================
  Files                  201      201              
  Lines                13868    13903      +35     
===================================================
+ Hits                 10460    10478      +18     
- Misses                3398     3415      +17     
  Partials                10       10              
Flag Coverage Δ
api:retry 9.07% <0.00%> (-0.03%) ⬇️
api:routes 8.84% <0.00%> (-0.03%) ⬇️
bucket-scanner 85.76% <ø> (ø)
ft_test:queuepopulator 10.97% <0.00%> (-0.03%) ⬇️
ingestion 12.27% <0.00%> (-0.04%) ⬇️
lib 7.76% <0.00%> (-0.05%) ⬇️
lifecycle 19.17% <0.00%> (-0.04%) ⬇️
notification 1.00% <0.00%> (-0.01%) ⬇️
oplogPopulator 0.13% <0.00%> (-0.01%) ⬇️
replication 18.80% <64.15%> (+0.06%) ⬆️
unit 54.33% <47.16%> (+0.56%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
@claude

claude Bot commented Jun 3, 2026

Copy link
Copy Markdown
  • package.json:54 — @scality/cloudserverclient uses a local file: path that will break CI and other developers. Must be changed to a proper npm or git-tag reference before merge.
    - extensions/replication/tasks/ReplicateObject.js:33-35 — Cascade sentinel objects (cascadeLoopDetected, cascadeDataComplete, partAlreadyAtDest) are plain {} singletons that pass through BackbeatTask.retry(), which mutates errors. Consider Object.freeze() to prevent accidental mutation.

    The cascade logic itself (putData/putMetadata detection, allPartsAlreadyAtDest propagation through the waterfall, _handleReplicationOutcome treating cascade signals as COMPLETED) is sound. The retry wrapper correctly passes cascade signals through without retrying (no retryable property). Tests cover the key scenarios well.

    Review by Claude Code

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
@claude

claude Bot commented Jun 5, 2026

Copy link
Copy Markdown
  • ReplicateObject.js:602 — Cascade sentinel objects (cascadeLoopDetected, cascadeDataComplete) are passed as err to callbacks. Verify that BackbeatTask._retry won't retry on these truthy-but-non-error sentinels, which would defeat the loop/stale detection.
    - ReplicateObject.js:433 — On error path in _getAndPutData, destLocations may contain partial results. The sentinel objects ({}) pass the filter and could reach _deleteOrphans with undefined keys. Likely harmless due to downstream filtering, but worth a defensive check.
    - ReplicateObject.js:1014 — _processQueueEntryRetryFull now passes allPartsAlreadyAtDest as mdOnly to _putMetadata, changing retry-full semantics from always-full to conditionally-metadata-only. Confirm this is intentional.
    - package.json:57 — Arsenal pinned to a raw commit hash instead of a tag. Should be updated to a tag once the Arsenal PR merges.
    - package.json:54 — scality-cloudserverclient-v1.0.9.tgz vendored as a binary blob in git. Prefer a registry or git-tag reference.
    - ReplicateObject.js:573 — Trailing whitespace.

    Review by Claude Code

Comment thread package.json Outdated
Comment thread package.json Outdated
@SylvainSenechal SylvainSenechal requested review from a team, benzekrimaha and maeldonn June 8, 2026 15:47
@scality scality deleted a comment from bert-e Jun 9, 2026
Comment thread extensions/replication/tasks/ReplicateObject.js
this._getAndPutPart(sourceEntry, destEntry, part, log, done);
}, (err, destLocations) => {
}, (err, partResults) => {
// partAlreadyAtDest signals data already at dest (cascade putData 409);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partAlreadyAtDest name is not correct : we cannot detect that a "part" is already at destination, only that there is already an object (i.e. a document in mongo with the specified key and versionId).
→ should really be objectAlreadyAtDest

....and it changes the logic a bit : when it happen (even on a single part), all successful parts must be deleted.

Suggested change
// partAlreadyAtDest signals data already at dest (cascade putData 409);
if (err) {
return this._deleteOrphans(destEntry, destLocations, log, () => cb(err));
}
const destLocations = (partResults || []).filter(result => result && result !== partAlreadyAtDest);
if (destLocations.length != partResults.length) {
// object already exist, release all parts then check if metadata needs to be updated
return this._deleteOrphans(destEntry, destLocations, log, () =>
cb(null, destLocations, true);
}
return this._deleteOrphans(destEntry, destLocations, log, () =>
cb(null, destLocations, false);

i.e. we cannot make a partial write of object data. To create the metadata, all parts must be known: so all of them must have been written successfully. If there is a "conflict" on any single part, it means another replicant has finished uploading parts and created the metadata document : so we must drop all the parts we wrote, and just update the object metadata if needed....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also please create followups to

  • ignore (other) error if a single part has a conflict
  • abort other parts upload as soon as we identify a conflict (i.e. imagine a 1000 parts object: if we have a conflict on first part, no point trying the other parts)
  • consider changing the putPartData protocol to create actual MPU parts (which can be garbage-collected by lifecycle after transfer is aborted), for extra safety (not strictly related to CRR, but best to track it)

@SylvainSenechal SylvainSenechal Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I rewrote this because I think from the start I overcomplicated it.
The flow is :
if any err or conflict : delete all written data, else we can all parts like usually.

For the follow up :

  • I already created the follow up to do an early exit on multi part upload
  • The error handling, I think no need for a follow up, I added it in the code by checking conflict before checking error (although maybe its a bit simplistic, it kinda raise some questions about whether we still want to act on the errors, at least logs, maybe more depending on the errors, not sure)
  • Created a ticket for putPartDataMPU https://scality.atlassian.net/browse/BB-801

});
}

_resolveVersionIdCollision(collisionErr, sourceEntry, destEntry, log) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole function is not correct in case of putData(Parts) : if we receive VersionIdCollision, it means there is already a object with this versionId.

  • We must not create or replace the metadata with the new data (data is immutable)
  • We must immediately delete whatever we already uploaded
  • The microVersionId comparison can be used only after this, to decide if we need to proceed with the metadata update (e.g. not the location, but the other fields: tags, ...) or can skip it

→ here the function is used to compute partAlreadyAtDest, which would make _getAndPutData silently "hide" the error if there is already some data at the destination BUT the metadata we are trying to replicate is newer.
→ _getAndPutData() should probably return the max/last microVersionId it received (in case of conflict) or nothing it is wrote all data successfully (i.e. no conflict)

(the logic here is what should happen on microVersionId conflict on metadata, not here on VersionIdConflict)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also in that case the x-scal-replication-content sent to cloudserver MUST not be DATA+METADATA anymore, but be "downgraded" to METADATA (to keep the existing data)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see this is a left over from some missunderstanding that I had.

This function can be completely removed, but before I do it, there is one thing i wanna confirm :

In the design, we said in case of putData collision, we would still do the putMetadata, and let cloudserver on putMetadata deal with stale microVersionId

But as you said, since with the putData error we get a microVersionId returned, it is possible for backbeat to do the comparison directly here to avoid a useless putMetadata.

So I wanna decide which thing we should do : I would prefer skipping the putMetadata in backbeat if its useless, but also I wonder if there was a specific reason (that i can't find) we went with the design of sending putMetada regardless of the result of putData ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I talked with Maël and review again, I'm removing this function and making the improvement to check the microversion id on conflict to avoid useless put metadata

Comment on lines +1019 to +1037
if (err instanceof MicroVersionIdAlreadyStoredException) {
log.info('replication completed via cascade loop: ' +
'object already at destination with the same revision',
{ entry: sourceEntry.getLogInfo() });
this._publishReplicationStatus(sourceEntry, 'COMPLETED', { kafkaEntry, log });
return done(null, { committable: false });
}
if (err instanceof StaleMicroVersionIdException) {
log.info('replication completed: destination already holds ' +
'this version with a newer revision',
{ entry: sourceEntry.getLogInfo() });
this._publishReplicationStatus(sourceEntry, 'COMPLETED', { kafkaEntry, log });
return done(null, { committable: false });
}
if (!err) {
log.debug('replication succeeded for object, publishing ' +
'replication status as COMPLETED',
{ entry: sourceEntry.getLogInfo() });
this._publishReplicationStatus(
sourceEntry, 'COMPLETED', { kafkaEntry, log });
this._publishReplicationStatus(sourceEntry, 'COMPLETED', { kafkaEntry, log });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do exactly the same in all 3 branches : do we need 2 errors and different logs?

if (!err || err instanceof ...) {
    log.debug('replication succeeded for object, publishing ' +
                'replication status as COMPLETED',
                { entry: sourceEntry.getLogInfo(), err });
    this._publishReplicationStatus(sourceEntry, 'COMPLETED', { kafkaEntry, log });
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thats what I had a few week ago + the logs but I got suggested a refactoring

Are you sure you want to drop log in case of conflicts on microVersionId ? Seems like something we might wanna know about in case of issue

@francoisferrand francoisferrand left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handling of MPU is not correct : each "replicant" must write their own object fully, there is no situation where 2 "sources" each replicate part of the data (nor a way for these to identify the data they have written). Each source create the metadata document with the parts they uploaded, so they MUST successfully upload all parts data and MUST not have a conflict on any part.

@bert-e

bert-e commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

The following reviewers are expecting changes from the author, or must review again:

Comment on lines +1019 to +1032
if (err instanceof MicroVersionIdAlreadyStoredException) {
log.info('replication completed via cascade loop: ' +
'object already at destination with the same revision',
{ entry: sourceEntry.getLogInfo() });
this._publishReplicationStatus(sourceEntry, 'COMPLETED', { kafkaEntry, log });
return done(null, { committable: false });
}
if (err instanceof StaleMicroVersionIdException) {
log.info('replication completed: destination already holds ' +
'this version with a newer revision',
{ entry: sourceEntry.getLogInfo() });
this._publishReplicationStatus(sourceEntry, 'COMPLETED', { kafkaEntry, log });
return done(null, { committable: false });
}

@francoisferrand francoisferrand Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a risk of creating orphans here, please create a followup:

  1. new object was created → try to replicate DATA+META
  2. putDataParts succeeds (no conflict)
  3. before we could put metadata, another site was able to putData (same as us, not metadata → impossible to detect conflict) and putMetadata
  4. putMetadata will thus fail with MicroVersionIdAlreadyStoredException/StaleMicroVersionIdException

→ in that case, data created in 2. must be deleted, i.e. call _deleteOrphans. _deleteOrphans MUST NOT be called if this was a META-only update / if we did not call putDataParts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I see, created this : https://scality.atlassian.net/browse/BB-802
Looking from afar i think it shouldn't be too hard to handle, I will address it when we merge this pr otherwise this one will never be merged

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
return cb(null, destLocations);
// When no new data locations were written, force metadata-only mode (noNewDataLocations)
// so cloudserver preserves the destination's existing location field instead of overwriting it
const noNewDataLocations = destLocations.length === 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU this still does not implement what was agreed in the MPU thread: if some parts return partAlreadyAtDest and some were written by us, destLocations is a partial list, noNewDataLocations is false, and we proceed to putMetadata with only the parts we wrote → corrupted location metadata at destination. A conflict on any part means another replicant already wrote the metadata: we must delete all the parts we uploaded and downgrade to a metadata-only update. i.e. the check should be destLocations.length !== partResults.length, not === 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry I had not addressed comments yet when you did the review I was on cloudserver, it's updated now

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
Comment on lines +731 to +732
MicroVersionId: entry.getMicroVersionId()
? encodeMicroVersionId(entry.getMicroVersionId()) : '',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the empty-string convention is one of the open topics on scality/cloudserver#6179. Is the shape settled now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep this is very intentional, using undefined would cause the sdk to not even send the header and would break the cascade replication. A bit fragile if you ask me but this is the current design

const { errors, jsutil, versioning } = require('arsenal');
const { ObjectMDLocation } = require('arsenal').models;
const { ReplicationConfiguration } = require('arsenal').models;
const { encode: encodeMicroVersionId, decode } = versioning.VersionID;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename both or neither; decode unqualified next to encodeMicroVersionId reads as if they operate on different things

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
@SylvainSenechal SylvainSenechal force-pushed the improvement/BB-767 branch 2 times, most recently from 38d87c8 to 29d498b Compare July 9, 2026 10:22
Comment on lines +732 to +735
if (err instanceof MicroVersionIdAlreadyStoredException ||
err instanceof StaleMicroVersionIdException) {
return cbOnce(err);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the condition here? Can't we just log the error (like all other errors) and pass it up in these case as well?
(the main difference is that we would get a ERROR log instead of INFO... and log here instead of in the continuation callback)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its nicer to keep, these arent unexpected errors, and they are logged already in the replication outcome.

I moved them with the if (err.ObjNotFound) above though, as its a similar situation : expected error

entry: destEntry.getLogInfo(),
error: destMvIdRaw.message,
});
return doneOnce(destMvIdRaw);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should still be a collision : even if we can't parse the microVersionID, we are still in the case "data already at destination", so we shoud still try to write the metadata anyway ?

(the only difference is that we can't really make the optimization of skipping the metadata updated if the microVersionId is already up to date on target)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I updated the code, this will be a situation where we still do a putMetadata.
I also moved the decoding to another place, more centralized

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
Comment on lines +467 to +475
// Another replicant already stored the object data
// Compare microVersionIds to decide what to do with metadata:
// - source is newer : proceed in metadata-only mode
// - same or older : skip putMetadata
const destMvId = collisionResult.destMvIdRaw;
const srcMvId = sourceEntry.getMicroVersionId() || null;
const isLoop = srcMvId === destMvId;
const isStale = destMvId !== null &&
(srcMvId === null || srcMvId > destMvId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is where compareMicroVersionId shines, please use the arsenal function:

  • it makes the intent explicit (just comparing micro version id)
  • the function should handle the corner cases itself ("null" micro version id...)
  • we don't actually need to differentiate loop vs stale here

It would look something like this, i.e. we skip if we receive the destination micro version id (field present and no parse error) AND the micro version id is newer or equal at destination

const skipPutMetadata = destMvId !== undefined && compareMicroVersoinId(sourceEntry.getMicroVersionId(), destMvId) <= 0;
return cb(null, [], true, skipPutMetadata);

if (err instanceof VersionIdCollisionException) {
const destMvIdRaw = err.microVersionId
? decodeMicroVersionId(err.microVersionId) : null;
if (destMvIdRaw instanceof Error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I wonder if it is best to do the decoding here, or just pass the field "verbatim" in the part and let _getAndPutData() decode

  • it would avoid useless decoding of every parts' microVersionId
  • it would increase locally (
  • but the code here still needs to make sure if forwards both the microVersionId "value" AND the information that the field was indeed provided

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
// update location, replication status and put metadata in
// target bucket
(destLocations, next) => {
(destLocations, noNewDataLocations, skipMetadata, next) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 2 parameters are not independent, there are actually only 3 cases:

  • no conflict (i.e. as before)
  • conflict with metadata already up to date
  • conflict but we have newer metadata which need to be replicated

not sure how best to handle this, maybe an object ("conflict") with the microVersionId : so we also improve locality by performing the microVersionId comparison (optimization) here?
undefined in the usual case (no conflict), don't even need the false like line 972
{ microVersionId: ... } (possibly with the "conflict" field you already have) otherwise ; skip if compareMicroVersionId() <= 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it with a conflict object and move some logic around into a helper function as we still need it in 2 different places

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
destEntry.setLocation(location);
this._putMetadata(destEntry, false, log, next);
(destLocations, noNewDataLocations, skipMetadata, next) => {
if (skipMetadata) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block is duplicated and not trivial (it handles putData conflict resolution) : should be written just once... does it makes sense do do this in _putMetadata, by adding it another parameter for putData conflict ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna refactor this but I prefer extracting a helper functoin that putting it in putMetadata.
It looks very weird to call a function with an object that's used at the top of the function so that the function itself decides whether it should conitnue or not

Comment thread extensions/replication/tasks/ReplicateObject.js Outdated
const replicationContent = (mdOnly ? 'METADATA' : undefined);
// Send x-scal-replication-content so cloudserver know the putMetadata api
// is used in the context of a replication
const replicationContent = (mdOnly ? 'METADATA' : 'DATA,METADATA');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required as otherwise, in non mdOnly situation, there is no replicationContent header, and cloudserver has no way no know we are calling putMetadata in the context of a replication.

Anyways i think sending data, metadata for non mdOnly should've been added earlier.

// holds this revision or a newer one. Returns false when there is no conflict,
// when the destination microVersionId is absent or can't be parsed (proceed
// conservatively), or when the source holds a newer revision.
_shouldSkipMetadata(sourceMicroVersionId, conflict, log) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discuss : Could be moved into putMetada so that we don't have to call this from 2 places, and instead inline it.

But imo it's a weird pattern to add an extra param to a function, then call that function and use that extra param at the top to decide to potentially not run this function

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either are fine with me.

  • while I agree on the param (especially the skip(bool skip) anti-pattern), in this case it seems fine to me : the parameter is not just an indication to skip, but really an input allowing to make the decision ("details of the conflict").
  • in my mind, putting it is putMetadata makes it a further from the anti-pattern : to me it is not skipping the metadata write, but just raising the abstraction level. PutMetadata's goal is to ensure the metadata is in the system, and it would gain the ability to reach the goal without actually making a write (kind of magic!) - similar in a way to how a getter could either read from the actual DB or quickly return the data from a cache.

(but either way may be better to keep _shouldSkipMetadata separate -just decide if it is called from within _putMetadata or before it- so each path can be demonstrated and tested easily)

@SylvainSenechal

Copy link
Copy Markdown
Contributor Author

The code is getting smaller after each review 😆
Retested in codespace after last push

}
}
const comparison = compareMicroVersionId(sourceMicroVersionId, destMvId);
return destMvId !== null &&

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May completely remove the null check if I end up update the compareMicroVersionId function.
Still reviewing cloudserver, haven't done it/decided yet

continue;
}
if (result.isCollision) {
collisionResult = collisionResult || result;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
collisionResult = collisionResult || result;
collisionResult ||= result;

return this._deleteOrphans(destEntry, destLocations, log, () => cb(err));
}, (err, partResults) => {
let collisionResult;
const nonCollisionParts = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
const nonCollisionParts = [];
const parts = [];

});
return doneOnce(null, {
isCollision: true,
destinationMicroVersionId: err.microVersionId,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the name simple here : the destination prefix adds verbosity, but does not improve readability IMHO

Comment on lines +482 to +484
return cb(null, [], {
microVersionId: collisionResult.destinationMicroVersionId,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could even return the collisionResult directly

Suggested change
return cb(null, [], {
microVersionId: collisionResult.destinationMicroVersionId,
});
return cb(null, [], collisionResult);

// CREATE a new document. Use METADATA when:
// - this is a metadata-only replication entry (mdOnly), or
// - data was already written to the destination from another path (conflict).
const localMdOnly = mdOnly || conflict !== undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would work the same if conflict is null ?

Suggested change
const localMdOnly = mdOnly || conflict !== undefined;
const localMdOnly = mdOnly || !!conflict;

const localMdOnly = mdOnly || conflict !== undefined;
destEntry.setLocation(destLocations);
this._putMetadata(destEntry, mdOnly, log, err => {
return this._putMetadata(destEntry, localMdOnly, log, err => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local (in variable name) is a technicality, which makes the variable name weird.
maybe the cleaner way is just keep things simple:

Suggested change
return this._putMetadata(destEntry, localMdOnly, log, err => {
return this._putMetadata(destEntry, mdOnly || !!conflict, log, err => {

// holds this revision or a newer one. Returns false when there is no conflict,
// when the destination microVersionId is absent or can't be parsed (proceed
// conservatively), or when the source holds a newer revision.
_shouldSkipMetadata(sourceMicroVersionId, conflict, log) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either are fine with me.

  • while I agree on the param (especially the skip(bool skip) anti-pattern), in this case it seems fine to me : the parameter is not just an indication to skip, but really an input allowing to make the decision ("details of the conflict").
  • in my mind, putting it is putMetadata makes it a further from the anti-pattern : to me it is not skipping the metadata write, but just raising the abstraction level. PutMetadata's goal is to ensure the metadata is in the system, and it would gain the ability to reach the goal without actually making a write (kind of magic!) - similar in a way to how a getter could either read from the actual DB or quickly return the data from a cache.

(but either way may be better to keep _shouldSkipMetadata separate -just decide if it is called from within _putMetadata or before it- so each path can be demonstrated and tested easily)

Comment on lines +1034 to +1036
const localMdOnly = conflict !== undefined;
destEntry.setLocation(destLocations);
return this._putMetadata(destEntry, localMdOnly, log, next);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: same as above

Suggested change
const localMdOnly = conflict !== undefined;
destEntry.setLocation(destLocations);
return this._putMetadata(destEntry, localMdOnly, log, next);
destEntry.setLocation(destLocations);
return this._putMetadata(destEntry, !!conflict, log, next);

log, done) {
if (err instanceof MicroVersionIdAlreadyStoredException ||
err instanceof StaleMicroVersionIdException) {
log.info('replication completed: object already at destination',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "object" may be ambiguous here, it is not about the object (~data) but really about the metadata revision ?

Suggested change
log.info('replication completed: object already at destination',
log.info('replication completed: metadata already at destination',

or

Suggested change
log.info('replication completed: object already at destination',
log.info('replication completed: metadata revision already at destination',

or skip the ambiguity (but maybe not clear)

Suggested change
log.info('replication completed: object already at destination',
log.info('replication completed: already at destination',

});
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add tests to verify _shouldSkipMetadata behavior directly in the different cases

  • no conflict
  • conflict with "invalid" microVersionId
  • conflict with missing microVersionId
  • conflict with newer/equal/older microVersionId
  • conflict with null microVersionId (either in conflict or in destination)

@bert-e

bert-e commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants